<template>
  <div class="app-container">

    <el-card style="border-radius: 10px">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="返修单号" prop="repairCode">
        <el-input
          v-model="queryParams.repairCode"
          placeholder="请输入返修单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="返修类型" prop="repairType">
        <el-select v-model="queryParams.repairType" placeholder="请选择返修类型" clearable>
          <el-option
            v-for="dict in dict.type.return_repair_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="返修状态" prop="repairStatus">
        <el-select v-model="queryParams.repairStatus" placeholder="请选择返修单状态" clearable>
          <el-option
            v-for="dict in dict.type.return_repair_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['rr:returnrepair:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="returnrepairList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="返修单号" align="center" prop="repairCode" width="150">
        <template slot-scope="scope">
          <el-button
              type="text"
              @click="handleView(scope.row)"
              v-hasPermi="['rr:returnrepair:query']"
          >{{scope.row.repairCode}}</el-button>
        </template>
      </el-table-column>

      <el-table-column label="返修来源" align="center" prop="repairType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.return_repair_type_paichan" :value="scope.row.repairType"/>
        </template>
      </el-table-column>

      <el-table-column label="关联单号" align="center" prop="qcSourceDocCode" width="150"/>

      <el-table-column label="物料编码" align="center" prop="itemCode" width="150"/>
      <el-table-column label="物料名称" align="center" prop="itemName" width="150"/>
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="单位" align="center" prop="unitOfMeasure" />
<!--      <el-table-column label="批次号" align="center" prop="batchCode" width="150"/>-->
      <el-table-column label="返修数量" align="center" prop="reworkNum" />
      <el-table-column label="图号" align="center" prop="drawNumber" />
      <el-table-column label="单据状态" align="center" prop="repairStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.return_repair_status" :value="scope.row.repairStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="计划完工日期" align="center" prop="plannedCompletionDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.plannedCompletionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" fixed="right" width="160">
        <template slot-scope="scope">
            <el-button
              v-if="scope.row.repairStatus == 'PREPARE'"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['rr:returnrepair:edit']"

            >修改</el-button>
          <el-button
            v-if="scope.row.repairStatus == 'PENDING'"
            type="text"
            icon="el-icon-edit"
            @click="handlePaiChan(scope.row)"
            v-hasPermi="['rr:returnrepair:edit']"
          >排产
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-video-play"
            @click="getConfirmPage(scope.row)"
            v-if="scope.row.repairStatus == 'PENDING'"
          >执行工单
          </el-button>
            <el-button
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-if="scope.row.repairStatus == 'PREPARE'"
                v-hasPermi="['rr:returnrepair:remove']"
            >删除</el-button>
            <el-button
                type="text"
                icon="el-icon-info"
                @click="handleView2(scope.row)"
                v-if="scope.row.repairStatus == 'FINISHED' || scope.row.repairStatus == 'APPROVING' || scope.row.repairStatus == 'CONFIRMED'"
                v-hasPermi="['rr:returnrepair:query']"
            >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改返修管理-返修工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="返修单号" prop="repairCode" >
              <el-input v-model="form.repairCode" placeholder="请输入返修单号" :disabled="optType !== 'add'"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="返修来源" prop="repairType">
              <el-select v-model="form.repairType" placeholder="请选择返修来源" @change="handleRepairTypeChange"
                         :disabled="optType !=='add'" style="width: 100%">
                <el-option
                    v-for="dict in dict.type.return_repair_type_paichan"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
<!--          :disabled="optType !== 'add'"-->
          <el-col :span="12" v-if="form.repairType">
            <el-form-item :label="form.repairType =='directly_add' ? '生产工单号':'异常汇报单号'" prop="qcSourceDocCode">
              <el-input v-model="form.qcSourceDocCode" placeholder="请输入关联单号" readonly >
                <el-button slot="append" v-if="optType == 'add'" icon="el-icon-search" @click="handleSelect" ></el-button>
              </el-input>
            </el-form-item>
          </el-col>
<!--          异常汇报单携带的-->
          <el-col :span="12" v-if="form.repairType =='abnormality_report'">
            <el-form-item label="生产工单号" prop="生产工单号">
              <el-input v-model="form.workorderCode" placeholder="请输入生产工单号" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="图号" prop="itemCode">
              <el-input v-model="form.drawNumber" placeholder="请输入物料编码" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品编码" prop="itemCode">
              <el-input v-model="form.itemCode" placeholder="请输入物料编码" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="itemName">
              <el-input v-model="form.itemName" placeholder="请输入物料名称" disabled/>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="规格型号" prop="specification">
              <el-input v-model="form.specification" placeholder="请输入规格型号" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input v-model="form.unitOfMeasure" placeholder="请输入单位" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="返修数量" prop="reworkNum" >
<!--              <el-input v-model="form.reworkNum" placeholder="请输入返修数量" />-->
              <el-input-number v-model="form.reworkNum"  :min="1" :max="90000000000" size="mini"  :disabled="optType !== 'add'" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="计划完工日期" prop="plannedCompletionDate" >
              <el-date-picker clearable :disabled="optType !== 'add' && optType !== 'edit'"
                              v-model="form.plannedCompletionDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              :default-value="new Date()"
                              placeholder="请选择计划完工日期">
              </el-date-picker>
            </el-form-item>
          </el-col>

        </el-row>
        <el-tabs type="border-card" v-if="routeVisible">
          <el-tab-pane label="组成工序">
            <Routeprocess  ref="processLine" :optType="optType" :repairId="form.id" :item-code="form.itemCode"></Routeprocess>
          </el-tab-pane>
        </el-tabs>
      </el-form>

      <div slot="footer" class="dialog-footer">

        <el-button type="primary" v-if="optType == 'edit'" @click="tijiao">提 交</el-button>
        <el-button type="primary" v-if="optType !== 'view'" @click="submitForm()">保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <WorkorderSelect ref="workSelect" @onSelected="onWorkorderSelected"></WorkorderSelect>
      <ColReportSelect ref="colReportSelect" @onSelected="onColReportSelected"></ColReportSelect>
    </el-dialog>
    <!-- 添加或修改生产工单对话框 -->
    <el-dialog :title="title" :visible.sync="open2" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" disabled>
        <el-row>
          <el-col :span="12">
            <el-form-item label="返修单号" prop="repairCode">
              <el-input v-model="form.repairCode" placeholder="请输入返修单号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="返修来源" prop="repairType">
              <el-select v-model="form.repairType" placeholder="请选择返修来源" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.return_repair_type_paichan"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" v-if="form.repairType">
            <el-form-item :label="form.repairType =='directly_add' ? '生产工单号':'异常汇报单号'" prop="qcSourceDocCode">
              <el-input v-model="form.qcSourceDocCode" placeholder="请输入关联单号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.repairType =='abnormality_report'">
            <el-form-item label="生产工单号" prop="生产工单号">
              <el-input v-model="form.workorderCode" placeholder="请输入生产工单号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="图号" prop="itemCode">
              <el-input v-model="form.drawNumber" placeholder="请输入物料编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品编码" prop="itemCode">
              <el-input v-model="form.itemCode" placeholder="请输入物料编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="itemName">
              <el-input v-model="form.itemName" placeholder="请输入物料名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="规格型号" prop="specification">
              <el-input v-model="form.specification" placeholder="请输入规格型号"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input v-model="form.unitOfMeasure" placeholder="请输入单位"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="返修数量" prop="reworkNum">
              <el-input-number v-model="form.reworkNum" :min="1" :max="90000000000" size="mini"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="计划完工日期" prop="plannedCompletionDate">
              <el-date-picker clearable
                              v-model="form.plannedCompletionDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              :default-value="new Date()"
                              placeholder="请选择计划完工日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="border-card" v-if="form.id != null">
        <el-tab-pane label="工艺流程">
          <div v-if="form.id != null" :class="this.processOptions.length > 4 ? 'scroll-mode' : 'equal-mode'">
            <el-steps class="steps-container" :active="activeProcess" v-if="form.id != null" align-center>
              <el-step
                v-for="(item, index) in processOptions"
                :key="item.processId"
                @click.native="handleStepClick(index)"
                :title="'工序' + (index + 1)"
                :description="item.processName"
              />
            </el-steps>
          </div>
          <el-card v-for="(item, index) in processOptions" :key="index" v-if="activeProcess == index">
            <template>
              <span>工序说明:</span>
              <span>{{ item.attr1 }}</span>
            </template>
            <RrTask
              :rrWorkorderId="form.id"
              :processId="item.processId"
              :colorCode="item.colorCode"
              :optType="optType"
              :quantity="form.quantity"
            ></RrTask>
          </el-card>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel" v-if="optType != 'view' && optType != 'confirm' && optType != 'finish'">保 存</el-button>
        <el-button type="danger" @click="handDofinish" v-if="optType == 'finish'">完 工</el-button>
        <el-button type="danger" @click="handleConfirm" v-if="optType == 'confirm'">执行工单</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listReturnrepair,
  getReturnrepair,
  delReturnrepair,
  addReturnrepair,
  updateReturnrepair,
  getRouteInfo, finishWork, editWorkAndLine
} from "@/api/mes/rr/returnrepair";
import { deleteByRepairId } from "@/api/mes/rr/retrunrepairline";

import Routeprocess from "@/views/mes/rr/returnrepairV2/routeprocess.vue";
import {getWsList} from "@/api/mes/md/workstation";
import {genCode} from "@/api/system/autocode/rule";
//生成工单
import WorkorderSelect from '@/components/workorderSelect/singleforRr.vue'
//异常汇报单
import ColReportSelect from "@/views/mes/rr/returnrepairV2/colreportselect.vue";
import {getMdItem, listMdItem} from "@/api/mes/md/mdItem";
import RrTask from "@/views/mes/rr/returnrepairV2/task/rrTask.vue";
import {listProcess} from "@/api/mes/rr/retrunrepairline";
export default {
  name: "Returnrepair",
  components: {RrTask, Routeprocess, WorkorderSelect, ColReportSelect},
  dicts: ['return_repair_status', 'return_repair_type_paichan'],
  data() {
    return {
      activeProcess: 0,
      processOptions: [],
      open2: false,
      disabled:false,
      routeVisible:false,
      workstationVisible:false,
      workstationsOptions:[],
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 返修管理-返修工单表格数据
      returnrepairList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        repairCode: null,        repairType: null,        repairStatus: null,        itemCode: null,        itemName: null,      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        repairType: [
          { required: true, message: "返修类型不能为空", trigger: "blur" }
        ],
        plannedCompletionDate: [
          { required: true, message: "计划完成日期不能为空", trigger: "blur" }
        ],
        reworkNum: [
          { required: true, message: "返修数量不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getWorkstation()
  },
  methods: {
    /** 查询返修管理-返修工单列表 */
    getList() {
      this.loading = true;
      listReturnrepair(this.queryParams).then(response => {
        this.returnrepairList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getWorkstation(){
      //获取工作张
      getWsList().then(response => {
        this.workstationsOptions=[]
        this.workstationsOptions = response.data;
        console.log("333333",this.workstationsOptions)
      });
    },
    //清空一下单据头基础数据
    reasetItem(){
      this.form.qcSourceDocCode = null;
      this.form.workorderId = null;
      this.form.workorderCode = null;
      this.form.workorderName = null;
      this.form.itemId= null;
      this.form.itemCode= null;
      this.form.itemName= null;
      this.form.specification= null;
      this.form.unitOfMeasure= null;
      this.form.drawNumber=null;
    },
    //选择生产工单
    handleSelect(){
      if(this.form.repairType){
        if(this.form.repairType == 'directly_add'){
          this.$refs.workSelect.showFlag = true;
        }
        if(this.form.repairType == 'abnormality_report'){
          this.$refs.colReportSelect.showFlag = true;
        }
      } else {
        this.$modal.msgWarning("请选择单据来源");
        return
      }

    },
    //选择生成工单
    onWorkorderSelected(row) {
      if (row != undefined && row != null) {
        this.reasetItem()
        this.form.qcSourceDocCode = row.workorderCode
        this.form.workorderId = row.workorderId;
        this.form.workorderCode = row.workorderCode;
        this.form.workorderName = row.workorderName;
        this.form.itemId=row.productId;
        this.form.itemCode=row.productCode
        this.form.itemName=row.productName
        this.form.specification=row.productSpc
        this.form.unitOfMeasure=row.unitOfMeasure
        this.form.drawNumber=row.attr2


      }
    },
    //选择异常汇报单
    onColReportSelected(row){
      if (row != undefined && row != null) {
        this.reasetItem()
        this.form.qcSourceDocCode = row.reportCode
        listMdItem({itemCode: row.itemCode}).then(response => {
          //因为异常汇总表里没有存itemid  用itemcode的list查的
          this.form.itemId=response.rows[0].itemId;
          this.form.itemCode=response.rows[0].itemCode;
          this.form.itemName=response.rows[0].itemName
          this.form.specification=response.rows[0].specification
          this.form.unitOfMeasure=response.rows[0].unitOfMeasure
          this.form.drawNumber=response.rows[0].drawNumber
          ;
        })
        // 异常汇报单中只有生成工单编号 ， workorderId workorderName 表中没有
        this.form.workorderCode = row.workorderCode;

      }

    },
    handleRepairTypeChange(value){
     //
      if('directly_add' == value){
        this.form.qcSourceDocCode=null
        this.workstationId=null
        this.workstationCode=null
        this.workstationName=null
      }
      // 线下返修  选择工作站即可
      if('abnormality_report' == value){
        this.form.qcSourceDocCode=null
        this.workstationId=null
        this.workstationCode=null
        this.workstationName=null
      }

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open2 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,        repairCode: null,        repairType: null,        repairStatus: 'PREPARE',    drawNumber:null,
        qcCode: null,        qcType: null,        qcSourceDocCode: null,        qcSourceDocType: null,        itemId: null,
        itemCode: null,        itemName: null,        specification: null,        unitOfMeasure: null,        batchCode: null,
        reworkNum: null,        plannedCompletionDate: new Date().toISOString().split('T')[0],        actualCompletionDate: null,        routeCode: null,
        routeName: null,        createBy: null,        createByName: null,        createTime: null,        updateBy: null,
        updateTime: null,        tenantId: null      };
      this.resetForm("form");
      this.routeVisible= false
      this.workstationVisible= false
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      genCode('RETURN_REPAIR_WORD_CODE').then(response => {
        this.form.repairCode = response;
      });
      this.optType = "add";
      this.open = true;
      this.title = "添加返修管理-返修工单";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.$nextTick(() => {
        getReturnrepair(id).then(response => {
          this.form = response.data;

          this.routeVisible= true
          this.open = true;
          this.optType='edit'
          this.title = "修改返修管理-返修工单";
        });
      })

    },
    /** 修改按钮操作 */
    handlePaiChan(row) {
      this.reset();
      getReturnrepair(row.id).then(response => {
        this.form = response.data;
        this.getProcess();
        this.open2 = true;
        this.title = '生产排产';
        this.optType = 'edit';
      });
    },
    handleView(row){
      this.reset();
      const id = row.id || this.ids
      getReturnrepair(id).then(response => {
        this.form = response.data;
        this.routeVisible= true
        this.disabled=true
        this.open = true;
        this.optType='view'
        this.title = "返修工单详情";
      });

    },
    tijiao(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            // 状态更改为待排产
            this.form.repairStatus="PENDING"
            const lineList = this.$refs.processLine.routeprocessList;
            console.log("subbbbbb",lineList)
            this.form.routProsessList=lineList
            editWorkAndLine(this.form).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            });
          } else{
            this.$modal.msgError("数据错误");
            return
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {

          if (this.form.id != null) {
            const lineList = this.$refs.processLine.routeprocessList;
            console.log("subbbbbb",lineList)
            this.form.routProsessList=lineList
            //修改时  单据头单据体同时跟新保存
            editWorkAndLine(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            //新增一个单据头
            addReturnrepair(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除返修管理-返修工单编号为"' + ids + '"的数据项？').then(function() {
        return delReturnrepair(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('rr/returnrepair/export', {
        ...this.queryParams
      }, `returnrepair_${new Date().getTime()}.xlsx`)
    },
    getProcess() {
      this.queryParams.repairId = this.form.id;
      listProcess(this.queryParams).then(response => {
        this.processOptions = response.data;
      });
    },
    //Step点击
    handleStepClick(index) {
      this.activeProcess = index;
    },
    getConfirmPage(row) {
      this.reset();
      const id = row.id || this.ids;
      getReturnrepair(id).then(response => {
        this.form = response.data;
        this.getProcess();
        this.open2 = true;
        this.title = '确认工单信息';
        this.optType = 'confirm';
      });
    },
    handleConfirm() {
      let that = this;
      that.$modal
        .confirm('是确认完成生产任务编制？【确认后将不能更改】')
        .then(function () {
          that.form.repairStatus = 'CONFIRMED';
          that.form.quantity = null;
          updateReturnrepair(that.form).then(() => {
            that.$modal.msgSuccess('修改成功');
            that.getList();
            that.open2 = false;
          })
            .catch(error => {
              console.error('updateWorkorder 执行失败：', error);
            });
        })
        .catch(() => {
        });
    },
    handDofinish() {
      const workorderIds = this.form.workorderId || this.ids;
      let msg = '是否确认完成工单？一旦完成，此工单将无法继续报工和入库';
      if (this.form.quantity != this.form.quantityProduced) {
        msg = '工单数量与实际生产数量不一致，是否确认完成工单，一旦完成，此工单将无法继续报工和入库？';
      }
      this.$modal.confirm(msg).then(() => {
        return dofinish(workorderIds);
      })
        .then(() => {
          this.getList();
          this.open = false;
          this.$modal.msgSuccess('更改成功');
        })
        .catch(() => {
        });
    },
    handleView2(row) {
      this.reset();
      const id = row.id || this.ids;
      getReturnrepair(id).then(response => {
        this.form = response.data;
        this.getProcess();
        this.open2 = true;
        this.title = '工单信息';
        this.optType = 'view';
      });
    },
  }
};
</script>
